package api_day11;

public class Ticket implements Runnable{
    //静态同步方法的实现
    private static int ticket = 100;
    @Override
    public void run() {
        while (true) {
            Ticket.sell();
            if (ticket == 0) break;
        }
    }
    //静态同步方法
    public static synchronized void sell(){
        Thread t = Thread.currentThread();
        String name = t.getName();
        if (ticket > 0){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(name + "正在卖票，当前售卖票号为：" + ticket);
            ticket--;
        }
    }
}